package ye.guo.huang.java9;

import java.io.IOException;
import java.time.ZoneId;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author: HUANG GY.
 * @Date: 2021/11/10 11:23
 * @Description: ye.guo.huang.java9
 */
public class Test03ProcessBuilder {

    public static void main(String[] args) throws IOException {
//        ProcessBuilder pb = new ProcessBuilder("notepad.exe");
        ProcessBuilder pb = new ProcessBuilder("C:\\01_software\\08_navicat121_premium_cs_x64\\install\\Navicat Premium 12\\navicat.exe");
        String np = "Not Present";
        Process p = pb.start();
        ProcessHandle.Info info = p.info();
        System.out.printf("Process ID : %s%n", p.pid());
        System.out.printf("Command name : %s%n", info.command().orElse(np));
        System.out.printf("Command line : %s%n", info.commandLine().orElse(np));

        System.out.printf("Start time: %s%n",
                info.startInstant().map(i -> i.atZone(ZoneId.systemDefault())
                        .toLocalDateTime().toString()).orElse(np));

        System.out.printf("Arguments : %s%n",
                info.arguments().map(a -> Stream.of(a).collect(
                        Collectors.joining(" "))).orElse(np));

        System.out.printf("User : %s%n", info.user().orElse(np));
    }

}